package service

import (
	"center-platform/internal/controller/v1/comment/entity"
)

type CommentImpl interface {
	//Info(id int) (error, *entity.Comment)
	List(param *entity.SearchParam) (error, []entity.Comment)
	Add(post *entity.Comment) error
}

type CommentService struct{}

//func (c *CommentService) Info(id int) (error, *entity.Comment) {

//}

func (c *CommentService) List(param *entity.SearchParam) (error, []entity.Comment) {
	var comment entity.Comment
	var where = " true"
	var args []interface{}
	limit := param.PageSize
	offset := (param.Page - 1) * limit
	if len(param.PostIds) > 0 {
		where += " and post_id in ?"
		args = append(args, param.PostIds)
	}

	if len(param.Status) > 0 {
		where += " and status in ?"
		args = append(args, param.Status)
	}
	if len(param.UserIds) > 0 {
		where += " and user_id in ?"
		args = append(args, param.UserIds)
	}

	err, lists := comment.List(where, offset, limit, args...)
	if err != nil {
		return err, nil
	}
	return nil, lists
}

func (c *CommentService) Add(post *entity.Comment) error {
	return post.Create()
}
